<?php

namespace app\modules\admin\controllers;

use app\core\YpBaseController;
use app\filters\AclFilter;
use yii;

class BaseController extends YpBaseController
{
    public $layout = 'admin';
    public $adminId ;
    public $adminName ;

    public function init()
    {
        parent::init();
        $this->checkIsLogin();
        $this->adminId = Yii::$app->session->get('_adminiUserId');
        $this->adminName = Yii::$app->session->get('_adminiUserName');
    }

    public function actions()
    {
        return [
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
            'upload' => [
                'class' => 'kucha\ueditor\UEditorAction',
            ],
        ];
    }

    /**
     * 行为
     */
    public function behaviors()
    {
        return [
            //访问权限过滤
            'access' => [
                'except' => ['forbidden', 'nopage'],
                'class'  => AclFilter::className(),
            ],
        ];
    }

    /**
     * 后台开启是否登录验证
     */
    public function checkIsLogin()
    {
        $adminiUserId = Yii::$app->session->get('_adminiUserId');
        $url          = Yii::$app->urlManager->createUrl('/admin/public/login');
        if (empty($adminiUserId)) {
            $this->redirect($url);
        }
    }
}
